[SPARK-56330][CORE][FOLLOWUP] Use dedicated loop for TaskInterruptListeners to avoid blocking completion listeners#55292
Closed
cloud-fan wants to merge 1 commit intoapache:masterfrom
Closed
Conversation
…teners to avoid blocking completion listeners Followup to apache#55151. The original implementation routes TaskInterruptListeners through the shared invokeListeners() method, which uses listenerInvocationThread to serialize all listener invocations. This creates a problem when markInterrupted() is called on the kill thread while completion listeners need to run on the task thread: the task thread sees listenerInvocationThread held by the kill thread and returns immediately, silently skipping all completion listeners. This can cause resource leaks because cleanup logic registered via addTaskCompletionListener (e.g., closing file handles, releasing caches, freeing native memory) never executes. Fix: use a dedicated loop for interrupt listeners that does not share listenerInvocationThread with completion/failure listeners. Exceptions are still collected and thrown as TaskCompletionListenerException so markInterrupted can catch and record the aggregate failure.
Contributor
Author
HyukjinKwon
approved these changes
Apr 12, 2026
Member
|
Merged to master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Followup to #55151.
Changed
invokeTaskInterruptListenersinTaskContextImplto use a dedicated loop instead of routing through the sharedinvokeListeners()method. Also removed the now-unnecessarymarkTaskFailedOnListenerErrorparameter frominvokeListenerssince it is alwaystrue(only completion and failure listeners use this method now).Why are the changes needed?
The current implementation routes
TaskInterruptListeners throughinvokeListeners(), which useslistenerInvocationThreadto serialize all listener invocations (completion, failure, and interrupt). This creates a problem whenmarkInterrupted()is called on the kill thread while completion listeners need to run on the task thread:invokeListeners()for interrupt callbacks and acquireslistenerInvocationThread.markTaskCompleted()→invokeTaskCompletionListeners()→invokeListeners()for completion callbacks.invokeListeners()seeslistenerInvocationThreadis held by the kill thread and returns immediately — silently skipping all completion listeners.This causes resource leaks because cleanup logic registered via
addTaskCompletionListener(e.g., closing file handles, releasing caches, freeing native memory) never executes.The fix uses a dedicated loop for interrupt listeners with independent serialization (synchronized access to the callback stack, but no
listenerInvocationThreadgate), so interrupt listeners and completion/failure listeners can run on different threads without blocking each other.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added a regression test
"SPARK-56330: task completion during interrupt listener execution"that:invokeListeners()approach).Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code